<?php
if (!class_exists("Config"))    include_once '../config/classes/class.Config.php';
$cfg = new config();
if (!class_exists("InfoElem"))      include_once $cfg->pathClasses."/class.InfoElem.php";

$error = false;
$id    = $_POST['id'];

$elem  = new Infoelem($id);
$elem->getFromBDById();

if ($elem->getLat() == "") {
    $error = true;
    $html  = "El elemento no existe <br>"; 
}

if (file_exists($cfg->pathElems."/img/".$elem->getFoto())) // si existe la antigua
{  
    if (unlink($cfg->pathElems."/img/".$elem->getFoto())) $error = false; //la borramos
    else  {
        $html  = "Error al eliminar la foto antigua!<br>";
        $error = true; 
    }
} 

if (!$error){
    if ($elem->deleteFromBD()) $error = false;
    else {
        $error = true; 
        $html = "Error borrando el elemento $id de la BBDD<br>";
    }
}


if (!$error) $html = "Elemento borrado con éxito<br>";


?>



<html>
<head>
    <title>ElectrolinerasOnline.com</title>         

    <!-- META -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=8">

    <!-- CSS -->
    <link rel="stylesheet" type="text/css" media="all" href="<?php echo $cfg->pathCss ?>/main2.css"/>      
    <link href='http://fonts.googleapis.com/css?family=Nunito:300' rel='stylesheet' type='text/css'> <!-- 'Nunito', sans-serif; -->
    <link href='http://fonts.googleapis.com/css?family=Convergence' rel='stylesheet' type='text/css'> <!-- 'Convergence', sans-serif; -->
    <link type="text/css" href="<?php echo $cfg->pathJs ?>/jqueryui/css/custom-theme/jquery-ui-1.8.17.custom.css" rel="stylesheet" />	
    <link type="text/css" href="<?php echo $cfg->pathJs ?>/DropKick/dropkick.css" rel="stylesheet" />	
    <link type="text/css" href="<?php echo $cfg->pathJs ?>/DropKick/example/example.css" rel="stylesheet" />	
    <link type="text/css" href="<?php echo $cfg->pathCss.'ezmark.css'?>" rel="stylesheet" />	
    <link rel="stylesheet" href="<?php echo $cfg->pathJs ?>/fancybox/source/jquery.fancybox.css?v=2.0.5" type="text/css" media="screen" />
    <link rel="stylesheet" href="<?php echo $cfg->pathJs ?>/fancybox/source/helpers/jquery.fancybox-buttons.css?v=2.0.5" type="text/css" media="screen" />
    <link rel="stylesheet" href="<?php echo $cfg->pathJs ?>/fancybox/source/helpers/jquery.fancybox-thumbs.css?v=2.0.5" type="text/css" media="screen" />

    <!-- SCRIPTS -->
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/jqueryui/js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/jqueryui/js/jquery-ui-1.8.17.custom.min.js"></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/common.js"></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/DropKick/jquery.dropkick-1.0.0.js"></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/jquery.ezmark.min.js"></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/fancybox/source/jquery.fancybox.pack.js?v=2.0.5"></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/fancybox/lib/jquery.mousewheel-3.0.6.pack.js"/></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/fancybox/source/helpers/jquery.fancybox-buttons.js?v=2.0.5"></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/fancybox/source/helpers/jquery.fancybox-thumbs.js?v=2.0.5"></script>
    
    <script>
        $(document).ready(function () {
            $("#btn_home").button();
        });
    
    </script>
        
</head>


<body>
    <div id="contenedor" class="container">

        <?php
            include $cfg->pathBackEnd."/header_sinlinks.php";
        ?>

        <div id="cuerpo" class="clear" style="padding-top: 70px;text-align: center">

            <script>
                var text = "<?php echo $html?>";
                
                <?php if ($error) { ?>
                            var type = "error";
                <?php } else { ?>
                            var type = "";
                <?php } ?>   
                    
                document.write(getMessageBox(text,"70%",type));    
                
            </script>
            
            <?php if ($error) { ?>
                    <img src="<?php echo $cfg->pathImg.'/sad.png' ?>"/>
            <?php } else { ?>
                    <img src="<?php echo $cfg->pathImg.'/happy.png' ?>"/>
            <?php } ?>    
                
            <br>
            
            <input type="button" id="btn_home" value="&laquo; Volver" style="margin:0px auto" onClick ="window.location.href='<?php echo $cfg->pathBackEnd ?>/home.php'"/>
                
            <div id="hidden_variables" class="oculto">

                <!-- En este bloque metemos el contenido del fancybox -->


                <?php //include $cfg->pathConfig."/users/add_new_elem.php"?>

                <div id="aux_hidden_div">

                </div>
            </div>
            
        </div>    

    </div>
</body>
</html>

